﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ResolverFactoryDefault.cs" company="Rolosoft Ltd">
//   © Rolosoft Ltd
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

#region License

// Copyright 2013 Rolosoft Ltd
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

namespace Rsft.Net.Dns
{
    #region Usings

    using Rsft.Net.Dns.Interfaces;

    #endregion

    /// <summary>
    ///     The resolver factory default.
    /// </summary>
    /// <remarks>
    ///     Composition root for Resolver.
    /// </remarks>
    internal static class ResolverFactoryDefault
    {
        #region Constructors and Destructors

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     The create.
        /// </summary>
        /// <returns>
        ///     The <see cref="IResolver" />.
        /// </returns>
        public static ResolverDefault CreateResolver()
        {
            var configuration = CreateConfigurationFactory().Create();

            var logger = CreateLoggerFactory().Create();

            return new ResolverDefault(CreateReaderFactory(), CreateCacheFactory(), configuration, logger);
        }

        /// <summary>
        /// Creates the resolver.
        /// </summary>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <returns>
        /// The <see cref="IResolver"/>.
        /// </returns>
        public static ResolverDefault CreateResolver(IConfiguration configuration)
        {
            var logger = CreateLoggerFactory().Create();
            return new ResolverDefault(CreateReaderFactory(), CreateCacheFactory(), configuration, logger);
        }

        #endregion

        #region Methods

        /// <summary>
        ///     Creates the cache factory.
        /// </summary>
        /// <returns>
        ///     The <see cref="ICacheFactory" />
        /// </returns>
        private static ICacheFactory CreateCacheFactory()
        {
            return new CacheFactoryNull();
        }

        /// <summary>
        ///     Creates the configuration factory.
        /// </summary>
        /// <returns>
        ///     The <see cref="IConfigurationFactory" />.
        /// </returns>
        private static IConfigurationFactory CreateConfigurationFactory()
        {
            return new ConfigurationFactoryDefault();
        }

        /// <summary>
        ///     Creates the logger factory.
        /// </summary>
        /// <returns>
        ///     The <see cref="ILoggerFactory" />.
        /// </returns>
        private static ILoggerFactory CreateLoggerFactory()
        {
            return new LoggerFactoryDefault();
        }

        /// <summary>
        ///     Creates the reader factory.
        /// </summary>
        /// <returns>
        ///     The <see cref="IRecordReaderFactory" />.
        /// </returns>
        private static IRecordReaderFactory CreateReaderFactory()
        {
            return new RecordReaderFactoryDefault();
        }

        #endregion
    }
}